﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class admin_edcategorylang : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        SqlCommand mySqlSelect = new SqlCommand("select * from category_lang where id = @id and lang = @lang", cn);
        mySqlSelect.CommandType = CommandType.Text;
        mySqlSelect.Parameters.AddWithValue("id", Request.QueryString["id"] != null ? Request.QueryString["id"].ToString() : "");
        mySqlSelect.Parameters.AddWithValue("lang", Request.QueryString["lang"] != null ? Request.QueryString["lang"].ToString() : "");
        try
        {
            SqlDataReader rd = mySqlSelect.ExecuteReader();
            if (rd.HasRows)
            {
                rd.Read();
                //lg.SelectedValue = !rd.IsDBNull(1) ? rd.GetString(1).ToString() : "";
                menu.Text = !rd.IsDBNull(2) ? rd.GetString(2).ToString() : "";
                title.Text = !rd.IsDBNull(3) ? rd.GetString(3).ToString() : "";
                cont.Value = !rd.IsDBNull(4) ? rd.GetString(4).ToString() : "";
            }
            rd.Close();
            cn.Close();
        }
        catch (Exception ex)
        {
            cn.Close();
            Console.WriteLine("Loi setValueFromDatabaseToForm : " + ex);
        }
    }

    protected void addbt_Click(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();

        SqlCommand mySqlSelect = new SqlCommand("update category_lang set menu = @menu, title = @title, content = @cont where id = @id and lang = @lang", cn);
        mySqlSelect.CommandType = CommandType.Text;

        SqlParameter desc = new SqlParameter("@cont", SqlDbType.NVarChar);
        desc.Value = cont.Value;

        SqlParameter id = new SqlParameter("@id", SqlDbType.BigInt);
        id.Value = Request.QueryString["id"];

        SqlParameter tit = new SqlParameter("@title", SqlDbType.NVarChar, 100);
        tit.Value = title.Text;

        SqlParameter me = new SqlParameter("@menu", SqlDbType.NVarChar, 100);
        me.Value = menu.Text;

        SqlParameter lg = new SqlParameter("@lang", SqlDbType.NVarChar, 2);
        lg.Value = Request.QueryString["lang"];

        mySqlSelect.Parameters.Add(desc);
        mySqlSelect.Parameters.Add(id);
        mySqlSelect.Parameters.Add(tit);
        mySqlSelect.Parameters.Add(lg);
        mySqlSelect.Parameters.Add(me);
        mySqlSelect.ExecuteNonQuery();
        cn.Close();
        info.Text = "Cập nhật dữ liệu thành công";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?page=qlcategorylang&id=" + Request.QueryString["id"]);
    }
}